/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ValloyEditorUI.java
 *
 * Created on Mar 2, 2009, 10:17:36 PM
 */

package uta.valloytoalloy;

import edu.mit.csail.sdg.alloy4whole.*;
/**
 *
 * @author vasr
 */
public class ValloyEditorUI extends javax.swing.JFrame {

    SimpleGUI asguiParent;
    /** The text editor. */
    
    /** Creates new form ValloyEditorUI */
    public ValloyEditorUI() {
        initComponents();


    }

    public ValloyEditorUI(SimpleGUI asgui) {
        initComponents();
        asguiParent = asgui;
        if(asguiParent != null)
        {
            jLabel_ConnectedWithAlloy.setText("Connection with Alloy Succeeded");

        }

    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        ValloyTextArea = new javax.swing.JTextArea();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        AlloyTextArea = new javax.swing.JTextArea();
        Cmd_ExtractClassHierarchy = new javax.swing.JButton();
        Cmd_OpenValloyFile = new javax.swing.JButton();
        cmd_GenerateAlloFunctions = new javax.swing.JButton();
        Cmd_ExportToAlloy = new javax.swing.JButton();
        Cmd_Exit = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel_ConnectedWithAlloy = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Valloy > Alloy Converter");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Valloy Context", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        ValloyTextArea.setColumns(20);
        ValloyTextArea.setRows(5);
        jScrollPane1.setViewportView(ValloyTextArea);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 382, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 366, Short.MAX_VALUE)
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Alloy Convertor", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        AlloyTextArea.setColumns(20);
        AlloyTextArea.setRows(5);
        jScrollPane2.setViewportView(AlloyTextArea);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 456, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 366, Short.MAX_VALUE)
        );

        Cmd_ExtractClassHierarchy.setText("Extract Class Hierarchy");
        Cmd_ExtractClassHierarchy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Cmd_ExtractClassHierarchyActionPerformed(evt);
            }
        });

        Cmd_OpenValloyFile.setText("Open...");
        Cmd_OpenValloyFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Cmd_OpenValloyFileActionPerformed(evt);
            }
        });

        cmd_GenerateAlloFunctions.setText("Generate Alloy Functions");
        cmd_GenerateAlloFunctions.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmd_GenerateAlloFunctionsActionPerformed(evt);
            }
        });

        Cmd_ExportToAlloy.setText("Export to Alloy");
        Cmd_ExportToAlloy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Cmd_ExportToAlloyActionPerformed(evt);
            }
        });

        Cmd_Exit.setText("Exit >");
        Cmd_Exit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Cmd_ExitActionPerformed(evt);
            }
        });

        jLabel1.setText("Version 1.0.0.0 a");

        jLabel_ConnectedWithAlloy.setText("Running as an Independent Application.");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(Cmd_OpenValloyFile)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(Cmd_ExtractClassHierarchy)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cmd_GenerateAlloFunctions))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(Cmd_ExportToAlloy)
                        .addGap(90, 90, 90)
                        .addComponent(Cmd_Exit)
                        .addGap(20, 20, 20))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel_ConnectedWithAlloy, javax.swing.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE)
                .addGap(491, 491, 491))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Cmd_OpenValloyFile)
                    .addComponent(Cmd_ExtractClassHierarchy)
                    .addComponent(cmd_GenerateAlloFunctions)
                    .addComponent(Cmd_Exit)
                    .addComponent(Cmd_ExportToAlloy))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel_ConnectedWithAlloy))
                .addGap(11, 11, 11))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void Cmd_ExtractClassHierarchyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Cmd_ExtractClassHierarchyActionPerformed
        // TODO add your handling code here:
        ValloyInputController.ExtractClassHierarchy(AlloyTextArea);
        
}//GEN-LAST:event_Cmd_ExtractClassHierarchyActionPerformed

    private void cmd_GenerateAlloFunctionsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmd_GenerateAlloFunctionsActionPerformed
        // TODO add your handling code here:
        ValloyInputController.GenerateAlloyFunctions(AlloyTextArea);
    }//GEN-LAST:event_cmd_GenerateAlloFunctionsActionPerformed

    private void Cmd_OpenValloyFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Cmd_OpenValloyFileActionPerformed
        // TODO Move this code to its own class
         //Read from file
        ValloyInputController.OpenValloyFile(ValloyTextArea, asguiParent);
    }//GEN-LAST:event_Cmd_OpenValloyFileActionPerformed

    private void Cmd_ExportToAlloyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Cmd_ExportToAlloyActionPerformed
        // TODO add your handling code here:
        ValloyInputController.ExportToAlloy();
}//GEN-LAST:event_Cmd_ExportToAlloyActionPerformed

    private void Cmd_ExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Cmd_ExitActionPerformed
        // TODO add your handling code here:
        System.exit(0); 
    }//GEN-LAST:event_Cmd_ExitActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ValloyEditorUI().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea AlloyTextArea;
    private javax.swing.JButton Cmd_Exit;
    private javax.swing.JButton Cmd_ExportToAlloy;
    private javax.swing.JButton Cmd_ExtractClassHierarchy;
    private javax.swing.JButton Cmd_OpenValloyFile;
    private javax.swing.JTextArea ValloyTextArea;
    private javax.swing.JButton cmd_GenerateAlloFunctions;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel_ConnectedWithAlloy;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    // End of variables declaration//GEN-END:variables

}
